/**
 * 
 */
package com.automation.demo.cucumber;

import static org.junit.Assert.assertEquals;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

/**
 * @author David
 *
 */
public class CloudStepdefs {
	
	private DesiredCapabilities capabillities = DesiredCapabilities.firefox();  
    
	  
    private WebDriver driver; 
    
    private WebElement search;
	
    @Given("^I am on Telstra Cloud Management Console login page$")
    public void I_go_to_Telstra_Cloud() {
    	try {
			driver = new RemoteWebDriver(new URL("http://localhost:4000/wd/hub"), capabillities);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
        driver.get("https://cloud.telstra.com/login.jsp"); 
        
    }
    
    @When("^I login successfully$")
    public void login() {
		search =driver.findElement(By.name("uname"));
        search.sendKeys("vitaonline");
        search = driver.findElement(By.name("password"));
        search.sendKeys("josharies");
        driver.findElement(By.id("login_standard")).click();
    }
    
    @Then("^I should see the dashboard page$")
    public void verify_dashboard() {
    	assertEquals("Dashboard - management console - Cloud Services", driver.getTitle());
    	driver.close();
    }
    
    @Then("^I click total$")
    public void click_total_button() {
    	driver.findElement(By.cssSelector("#dashStatus div.total.clickable")).click();
    }
    
    @Then("^I should see virtual servers page$")
    public void verify_virtual() {
    	assertEquals("Virtual servers - management console - Cloud Services", driver.getTitle());
    	driver.close();
    }

}
